home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 266_01 / conlib.c < prev    next >
C/C++ Source or Header  |  1990-07-03  |  19KB  |  599 lines

  1. /*  PLOX keyword handling modules  04-21-90       FILE: CONLIB.C
  2.          Robert L. Patton, Jr.
  3.          1713 Parkcrest Terrace
  4.          Arlington, TX 76012
  5. */
  6. #define HOLD 10
  7. #define FNLEN 15
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include "PLOX.H"
  12. #include "CONLIB.H"
  13. #include "DATLIB.H"
  14. #include "DRAWLIB.H"
  15. #include "PXLIB.H"
  16. #include "WORDLIB.H"
  17.                            /* Global scaling parameters */
  18. static SCALING Xfit = {0.0,20.0,4.32},
  19.                Yfit = {0.0,25.0,2.88};
  20. static int     Xlen = 6*INCH-1, Ylen = 4*INCH-1;
  21.  
  22. /*   ======= */
  23. void Unknown (Word)
  24. /*   ======= */
  25. char *Word;
  26. {
  27. char Phrase[31] = "  unknown keyword: ";
  28.   strncat (Phrase,Word,12);
  29.   PauseMsg (Phrase);
  30. }
  31. /*   ===== */
  32. void ARcon (Sentence)
  33. /*   =====           Handles an AREA specification */
  34. char *Sentence;
  35. {
  36.   #define INSET INCH/2
  37.   char       Word[HOLD+1];
  38.   double     Xarea, Yarea, Xsize, Ysize;
  39.   static int Xa, Ya;
  40.   int        Border;
  41.  
  42.   #ifdef DEBUG
  43.   printf("ARcon:%s\n",Sentence);
  44.   #endif
  45.  
  46.   GetWord (Sentence, Word, HOLD);
  47.   Xa = INSET; Xlen = XMAX - 2 * INSET;
  48.   Ya = INSET; Ylen = YMAX - 2 * INSET;
  49.   Border = NO;
  50.   while (Word[0] != ' ') {
  51.  
  52.     if (EQUAL (Word,"at")) {
  53.       GetVal (Sentence, &Xarea);
  54.       GetVal (Sentence, &Yarea);
  55.       if (Xarea<=0 || Yarea<=0)
  56.         PauseMsg("  invalid AREA location, default used ");
  57.       else {
  58.         Xa = PIXELS (Xarea);
  59.         Ya = PIXELS (Yarea);
  60.       }
  61.     }
  62.     else if (EQUAL (Word,"size")) {
  63.       GetVal (Sentence, &Xsize);
  64.       GetVal (Sentence, &Ysize);
  65.       if (Xsize==0 || Ysize==0)
  66.         PauseMsg("  invalid AREA size, default used");
  67.       else {
  68.         Xlen = PIXELS (Xsize);
  69.         Ylen = PIXELS (Ysize);
  70.       }
  71.     }
  72.     else if (EQUAL (Word,"outline")) Border = YES;
  73.  
  74.     else Unknown (Word);
  75.  
  76.     GetWord (Sentence, Word, HOLD);
  77.   }
  78.   PX_Origin (Xa, Ya);
  79.   if (Border) Box (0, 0, Xlen, Ylen);
  80. }
  81. /*@@                                     CONLIB-2 */
  82. /*   ===== */
  83. void AXcon (Sentence)
  84. /*   =====           Handles an AXIS specification */
  85. char *Sentence;
  86. {
  87.   #define EXACT 1
  88.   char       Dir, Locus, Word[HOLD+1];
  89.   double     From, To;
  90.   int        Axlen, Boxes, Side, Visible, Xa, Ya;
  91.   SCALING    AxFit;
  92.  
  93.   #ifdef DEBUG
  94.   printf("AXcon:%s\n",Sentence);
  95.   #endif
  96.  
  97.   GetWord (Sentence, Word, HOLD);
  98.  
  99.                    /* Set all defaults */
  100.  
  101.   From = 0.0;  To = 0.0;  Boxes = 0;
  102.   Locus = 'L'; Dir = 'V', Side = -1;
  103.   Visible = YES;
  104.                           /* Interpret the specification */
  105.   while (Word[0] != ' ') {
  106.  
  107.       if      (EQUAL (Word,"invisible")) Visible = NO;
  108.       else if (EQUAL (Word,"above")) {Locus='A' ;Dir='H'; Side=-1;}
  109.       else if (EQUAL (Word,"below")) {Locus='B' ;Dir='H'; Side= 1;}
  110.       else if (EQUAL (Word,"right")) {Locus='R' ;Dir='V'; Side= 1;}
  111.       else if (EQUAL (Word,"left"))  {Locus='L' ;Dir='V'; Side=-1;}
  112.       else if (EQUAL (Word,"boxes")) GetInt (Sentence, &Boxes);
  113.       else if (EQUAL (Word,"from")) GetVal (Sentence, &From);
  114.       else if (EQUAL (Word,"to"))  GetVal (Sentence, &To);
  115.       else Unknown (Word);
  116.  
  117.       GetWord (Sentence, Word, HOLD);
  118.   }
  119.   Axlen = (Dir=='V'? Ylen: Xlen);
  120.   Xa = (Locus=='R'? Xlen: 0);
  121.   Ya = (Locus=='A'? Ylen: 0);
  122.   if (From==0.0 && To==0.0) {
  123.     PauseMsg("  axis range not given, using 0 to 100");
  124.     To = 100.0;
  125.   }
  126.   Scale (From, To, Axlen, EXACT, &Boxes, &AxFit);
  127.   if (Dir == 'H') CopyScale (&AxFit, &Xfit);
  128.   else            CopyScale (&AxFit, &Yfit);
  129.   if (Visible) AxNum (Xa, Ya, Dir, Side, Axlen, &AxFit, Boxes);
  130. }
  131. /*@@                                       CONLIB-3 */
  132. void BRcon (Sentence)
  133. /*   =====           Handles a BAR specification */
  134. #define BRBUF  12
  135. char *Sentence;
  136. {
  137.   double  Value;           /* local storage */
  138.   double  Width;           /* user bar spec */
  139.   float   Base;
  140.   float   *Xptr, *Yptr;    /* pointers to plot data */
  141.   char    Word[BRBUF+1];   /* local string storage */
  142.   char    Fname[FNLEN+1];  /* file name for data */
  143.   char    Dtype[MAXITEMS]; /* data type for any item */
  144.   char    Dir;             /* bar direction (H,V) */
  145.   int     Ix, Iy;          /* item no. in data line */
  146.   int     Foot, Thick;     /* pixel bar specs */
  147.   int     Rank, Of, Offset;/* abutted bar specs */
  148.   int     Xfoot, Yfoot;    /* local storage */
  149.   int     Xbar, Ybar;
  150.   int     BaseSet;         /* flag for user set base */
  151.   int     Points;          /* no. of data points */
  152.   int     Hatch, Gap;      /* bar hatch pattern code */
  153.   int     k;               /* local storage */
  154.  
  155.   #ifdef DEBUG
  156.   printf("BRcon:%s\n",Sentence);
  157.   #endif
  158.  
  159.   GetWord (Sentence, Word, BRBUF);
  160.  
  161.                  /* set defaults */
  162.   Fname[0] = ' ';
  163.   for (k=0; k<MAXITEMS; k++) Dtype[k] = 'N';
  164.   Ix = 1;         Iy = 2;
  165.   Width = .125;   Dir = 'V';  BaseSet = NO;
  166.   Rank = 1;       Of = 1;
  167.   Hatch = 0;      Gap = 4;
  168.                         /* Interpret specification */
  169.   while (Word[0]!=' ') {
  170.       if      (EQUAL (Word,"file"))  GetWord (Sentence, Fname, FNLEN);
  171.       else if (EQUAL (Word,"items")) SetItems (Sentence, &Ix, &Iy);
  172.       else if (EQUAL (Word,"item"))  SetDtype (Sentence, Dtype);
  173.       else if (EQUAL (Word,"base")) {GetVal (Sentence, &Value);
  174.                                      Base = (float) Value;
  175.                                      BaseSet = YES; }
  176.       else if (EQUAL (Word,"width")) GetVal (Sentence, &Width);
  177.       else if (EQUAL (Word,"hor") ||
  178.                EQUAL (Word,"H")          ) Dir = 'H';
  179.       else if (EQUAL (Word,"ver") ||
  180.                EQUAL (Word,"V")          ) Dir = 'V';
  181.       else if (EQUAL (Word,"hatch")) {
  182.                 GetWord (Sentence, Word, BRBUF);
  183.                 if      (EQUAL (Word,"H") ||
  184.                          EQUAL (Word,"hor"))    Hatch = 1;
  185.                 else if (EQUAL (Word,"V") ||
  186.                          EQUAL (Word,"ver"))    Hatch = 2;
  187.                 else if (EQUAL (Word,"right"))  Hatch = 3;
  188.                 else if (EQUAL (Word,"left"))   Hatch = 4;
  189.                 else if (EQUAL (Word,"square")) Hatch = 5;
  190.                 else if (EQUAL (Word,"blank"))  Hatch = 6;
  191.                 else    Unknown (Word);
  192.       }
  193.       else if (EQUAL (Word,"gap")) {
  194.                 GetInt (Sentence, &Gap);
  195.                 if (Gap <= 0) {
  196.                   PauseMsg ("  positive number must follow 'gap'");
  197.                   Gap = 4;
  198.                 }
  199.       }
  200. /*@@                                    CONLIB-4 */
  201.       else if (EQUAL (Word,"abut")) {
  202.                 GetInt (Sentence, &Rank);
  203.                 GetInt (Sentence, &Of);
  204.                 if (Rank > Of || Rank <= 0) {
  205.                   PauseMsg ("  error in abut specification");
  206.                   Rank = 1; Of = 1;
  207.                 }
  208.       }
  209.       else    Unknown (Word);
  210.       GetWord (Sentence, Word, BRBUF);
  211.   }
  212.                            /* Draw bars */
  213.   if (Fname[0]==' ')
  214.     PauseMsg("  no data file given - no bars drawn");
  215.   else {
  216.     GetTwo (Fname, &Xptr, Dtype[Ix-1], Ix, &Yptr, Dtype[Iy-1], Iy);
  217.     Points = (int) *Xptr;
  218.     if (Points == 0) {printf("  no data found for: "); PauseMsg(Fname);}
  219.     else {
  220.       PX_Style (Hatch, Gap);
  221.       Thick = PIXELS (Width);
  222.       Offset = (Thick * ((Rank<<1) - Of - 1)) / 2;
  223.       if (BaseSet) Foot = Scaled (&Base, Dir=='V'? &Yfit: &Xfit);
  224.       else         Foot = 0;
  225.       printf("  drawing %d bars\n",Points);
  226.       for (k=1; k<=Points; k++) {
  227.         Xbar = Scaled (++Xptr, &Xfit);
  228.         Ybar = Scaled (++Yptr, &Yfit);
  229.         if (Dir == 'V') {Xbar += Offset; Xfoot = Xbar; Yfoot = Foot;}
  230.         else            {Ybar += Offset; Xfoot = Foot; Yfoot = Ybar;}
  231.         Bar (Xfoot, Yfoot, Xbar, Ybar, Dir, Thick, Hatch, Gap);
  232.       }
  233.     }
  234.   }
  235. }
  236. /*@@                                      CONLIB-5 */
  237. void IScon (Sentence)
  238. /*   =====           Handles an ISO (gram) specification */
  239. #define ISBUF  12
  240. char *Sentence;
  241. {
  242.  
  243.   float   Xdata[3];        /* isogram line x points */
  244.   float   Ydata[3];        /* isogram line y points */
  245.   char    Vword[ISBUF+1];  /* local string storag